package com.zcc.makingfriend.controller;

import com.zcc.makingfriend.dao.PrivateChat;
import com.zcc.makingfriend.dao.User;
import com.zcc.makingfriend.dto.PrivateChatDto;
import com.zcc.makingfriend.service.PrivateChatService;
import com.zcc.makingfriend.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zcc
 */
@Api(tags = "私聊管理")
@RestController
@RequestMapping("/privateChat")
public class PrivateChatController {
    @Autowired
    PrivateChatService privateChatService;

    @ApiOperation("私聊")
    @PostMapping("/privateChat")
    public Result privateChat(@RequestBody PrivateChat privateChat){
        int i = privateChatService.addPrivateChat(privateChat);
        if (i == 1) {
            return Result.success("私聊成功");
        }
        return Result.fail("私聊失败");
    }

    @ApiOperation("取消私聊")
    @PostMapping("/disPrivateChat")
    public Result disPrivateChat(@RequestBody PrivateChat privateChat){
        int i = privateChatService.deletePrivateChat(privateChat);
        if (i == 1) {
            return Result.success("取消私聊成功");
        }
        return Result.fail("取消私聊失败");
    }

    @ApiOperation("获取私聊用户信息")
    @GetMapping("/getPrivateChat/{userId}")
    public Result getPrivateChat(@PathVariable Long userId){
        List<PrivateChatDto> privateChat = privateChatService.getPrivateChat(userId);
        return Result.success(privateChat);
    }
}
